<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" session="false" %><%@
include file="/WEB-INF/jspf/import.jspf" %>
<!doctype HTML>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
        <title> 车友会任务奖励 </title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta name="author" content="xieyongshuang_gz zhongqingbiao_gz"/>
        <link rel="stylesheet" type="text/css" href="http://js.3conline.com/wap/pcauto/2014/touch/club/club.css">
    </head>
    <body class="g-doc">
        <!--栏目计数器/文章计数器-->
         <jsp:include page="/template/wap/common/counter.jspf">
            <jsp:param name="channel" value="7840" />
        </jsp:include>
         <%@include file="../common/intf6007.html" %>
        <!-- 公共头部 -->
        <div class="g-hd">
            <a href="http://m.pcauto.com.cn" class="header-home" title="太平洋汽车网"></a>
            <div class="header-title">
                <span class="header-title-nav">
                    <a href="${WAPROOT}/">车友会</a> 
                    &gt; 任务奖励
                </span>
            </div>
        </div>
        <div class="g-th">新手任务</div>
        <div id="disposableTask" class="m-tasklist"> 
        </div>
        <div class="g-th">普通任务</div>
        <div id="normalTask"  class="m-tasklist">           
        </div>
        <div class="g-mack" id="j-g-mack"></div>
        <div class="g-pop" id="j-g-pop">
            <div class="g-pop-con">
                <a class="close" onclick="hidePop()"></a>
                <img id="j-pop-img" width="50" height="50" src="">
                <p class="des" id="j-pop-des"></p>
                <p class="status" id="j-pop-status"></p>
            </div>
            <div class="g-pop-btn" id="j-pop-btn"></div>
        </div>

        <div class="g-mack" id="j-g-mack2"></div>
        <div class="g-pop" id="j-g-pop2">
            <div class="g-pop-con2" id="j-pop-con2">
                <div class="g-pop-ah">领取失败</div>
                <div class="g-pop-des">抱歉，网络不给力</div>
            </div>
            <div class="g-pop-btn" id="j-pop-btn"><a href="javascript:void(0)" onclick="hidePop2()">我知道了</a></div>
        </div>

        <div id="Jfoot" class="g-footer">
            <!-- 公共底部 -->
            <%@include file="../common/intf5987.html" %>
            <script type="text/javascript" src="http://js.3conline.com/wap/2013/common/js/zepto1.1.min.js" ></script>
        </div>
        <script type="text/javascript">
            $(function(){ 	   
                fillTaskInfo();
            }); 
            var isClickRecieveBtn =   {};
            //填充新手任务和普通任务信息
            function fillTaskInfo(){ 
                $.getJSON("${TASKROOT}/intf/clubgc/taskList.do?req_enc=utf-8&resp_enc=utf-8&callback=?", null, function(taskList){
                    $.getJSON("${TASKROOT}/intf/clubgc/taskProgress.do?req_enc=utf-8&resp_enc=utf-8&callback=?", null, function(taskProgress){
                        taskProgressCallBack(taskProgress,taskList.disposableTask,taskList.normalTasks);
                    });
                });
                function taskProgressCallBack(progressArr,disposableTasks,normalTasks){
                    //新手任务
                    for (var key in disposableTasks){
                        for (var i in progressArr){
                            if(disposableTasks[key].taskId == progressArr[i].taskId){
                                var item = getOneTask(progressArr[i],disposableTasks[key]);
                                $("#disposableTask").append(item);
                            }
                        }
                        isClickRecieveBtn[disposableTasks[key].taskId]=false;
                    }	  
                    //普通任务
                    for (var key in normalTasks){
                        for (var i in progressArr){
                            if(normalTasks[key].taskId == progressArr[i].taskId){
                                var item = getOneTask(progressArr[i],normalTasks[key]);
                                $("#normalTask").append(item);
                            }
                        }
                        isClickRecieveBtn[normalTasks[key].taskId]=false;
                    }   
                    function getOneTask(progress,task){
                        var statusHtml = "<span>"+progress.current +"/"+ task.limitDaily+"</span>";
                        if(progress.received == 1){
                            statusHtml = '<span class="got">已领取</span>';            			   
                        }
                        if(progress.status==1 && progress.received==0){
                            statusHtml = '<a class="get" href="javascript:void(0)" onclick="recieveGoldCoin('+ progress.taskId +');">领取奖励</a>';    
                        }
                        var oneTask='<div class="m-task-item">'
                            +'<a class="m-task-item-a" taskid="'+ task.taskId+'" href="javascript:void(0)">'
                            +'<img  width="50" height="50" src=""/>'
                            +'<p class="tit"></p>'
                            +'<p class="gold"></p>'
                            +'<input type="hidden" class="imgSrc" value=""/>'
                            +'<input type="hidden" class="desTxt" value=""/>'
                            +'<input type="hidden" class="statusTxt" value="">'
                            +'<input type="hidden" class="btnTxt" value=""/>'
                            +'<input type="hidden" class="btnUrl" value=""/>'
                            +'</a>'
                            +'<p class="m-task-item-b" id=\'task_'+ task.taskId +'\'>'
                            + statusHtml
                            +'</p>'
                            +'</div>';
                        var $oneTask = $(oneTask);
                        $oneTask.find("img").attr("src",task.applogo);
                        $oneTask.find("input.imgSrc").val(task.applogo);
                        $oneTask.find("p.tit").text(task.taskName);
                        $oneTask.find("p.gold").text("+"+task.gold);
                        $oneTask.find("input.desTxt").val(task.wapAction.desc);
                        $oneTask.find("input.statusTxt").val( progress.current +"/"+ task.limitDaily);
                        $oneTask.find("input.btnTxt").val(task.wapAction.text);
                        $oneTask.find("input.btnUrl").val(task.wapAction.url);
                        return $oneTask;
                    }
                }
            }
           
            var elem_bg=document.getElementById('j-g-mack');
            var elem_pop=document.getElementById('j-g-pop');
            var elem_des=document.getElementById('j-pop-des');
            var elem_status=document.getElementById('j-pop-status');
            var elem_btn=document.getElementById('j-pop-btn');
            var elem_img=document.getElementById('j-pop-img');
            elem_bg.style.height = document.documentElement.clientHeight + 70 + "px";
            $(".m-task-item-a").live('click',function(){
                if(($(this).attr("taskid")=="2"||$(this).attr("taskid")=="3")&&${!isMember}){
                    showPop2('<div class="g-pop-ah">领取失败</div> <div class="g-pop-des">请先加入一个车友会</div>');
                    return ;
                }
                var imgSrc=$(this).find(".imgSrc").attr("value"),
                desTxt=$(this).find(".desTxt").attr("value"),
                statusTxt=$(this).find(".statusTxt").attr("value"),
                btnTxt=$(this).find(".btnTxt").attr("value"),
                btnUrl=$(this).find(".btnUrl").attr("value");
                elem_img.src=imgSrc;
                elem_des.innerHTML=desTxt;
                elem_status.innerHTML=statusTxt;
                elem_btn.innerHTML='';
                if(btnTxt && btnUrl ){
                    elem_btn.innerHTML='<a href="'+btnUrl+'">'+btnTxt+'</a>';
                }else{
                    elem_btn.innerHTML='<a href="javascript:hidePop();">好的</a>';
                }
                elem_bg.style.display=elem_pop.style.display="block";
            });
            function hidePop(){
                elem_bg.style.display=elem_pop.style.display="none";
            }
            elem_bg.onclick=function(){
                hidePop(); 
            }
            
            //领取金币
            function recieveGoldCoin(taskId){
                if(!isClickRecieveBtn[taskId]){//避免重复点击
                    isClickRecieveBtn[taskId]=true;
                    $.ajax({
                        url:"${WAPROOT}/task/intf/clubgc/recieveGoldCoin.do?req_enc=utf-8&resp_enc=utf-8",
                        data:{taskId:taskId},
                        dataType:"json",
                        type:"post",
                        success:function(data){
                        if(data.status == 0){
                            showPop2('<div class="g-pop-ah g-pop-ah-s">领取成功</div>');
                            $("#task_"+taskId).html('<span class="got">已领取</span>'); 
                        }else if(data.code == 1){
                            showPop2('<div class="g-pop-ah">领取失败</div> <div class="g-pop-des">请先登录</div>'); 
                        }else if(data.code == 2){
                            showPop2('<div class="g-pop-ah">领取失败</div> <div class="g-pop-des">抱歉，您的帐号不符合领取资格！</div>'); 
                        }else if(data.code == 3){
                            showPop2('<div class="g-pop-ah">领取失败</div> <div class="g-pop-des">抱歉，请刷新页面再试一次</div>'); 
                        }else{
                            showPop2('<div class="g-pop-ah">领取失败</div> <div class="g-pop-des">抱歉，网络不给力</div>'); 
                        }
                        isClickRecieveBtn[taskId]=false;
                    },
                        error:function(){
                             showPop2('<div class="g-pop-ah">领取失败</div> <div class="g-pop-des">抱歉，网络不给力</div>'); 
                             isClickRecieveBtn[taskId]=false;
                        }
                    });
                }
            }
            //领取奖励成功或失败
            var elem_bg2=document.getElementById('j-g-mack2');
            var elem_pop2=document.getElementById('j-g-pop2');
            var elem_con2=document.getElementById('j-pop-con2');
            elem_bg2.style.height = document.documentElement.clientHeight + 70 + "px";
            function showPop2(tip){               
                elem_bg2.style.display=elem_pop2.style.display="block";
                elem_con2.innerHTML=tip;
            }
            function hidePop2(){
                elem_bg2.style.display=elem_pop2.style.display="none";
            }

        </script>

    </body>
</html>